//
//  ViewController.m
//  iOS_use_HTML
//
//  Created by leo on 16/2/20.
//  Copyright © 2016年 leo. All rights reserved.
//

#import "ViewController.h"

@interface ViewController () <UIWebViewDelegate>
@property (weak, nonatomic) IBOutlet UIWebView *webView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 本地加载网页
    NSURL *url = [[NSBundle mainBundle] URLForResource:@"index" withExtension:@"html"];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    
    [self.webView loadRequest:request];
    
}

#pragma mark - 操作网页
- (void)webViewDidFinishLoad:(UIWebView *)webView {
    // 删除
    NSString *str1 = @"var word = document.getElementById('word');";
    NSString *str2 = @"word.remove();";
    
    [webView stringByEvaluatingJavaScriptFromString:str1];
    [webView stringByEvaluatingJavaScriptFromString:str2];
    
    // 更改
    NSString *str3 = @"var change = document.getElementsByClassName('change')[0];"
        "change.innerHTML = '走你!';";
    [webView stringByEvaluatingJavaScriptFromString:str3];
    
    // 插入
    NSString *str4 = @"var img = document.createElement('img');"
        "img.src = 'img_01.jpg';"
        "img.width = '160';"
        "img.height = '80';"
        "document.body.appendChild(img);";
    [webView stringByEvaluatingJavaScriptFromString:str4];
    
}

@end
